#读取链接库的链接,随机选出一条
import os
import random
from web.settings import BASE_DIR
def KW_readlinks():  #返回列表
    try:
        wordlist = []
        path = os.path.join(BASE_DIR, 'newsblog\\VIPsetkeyword\\links.txt')
        for line in open(path, encoding='utf-8'):
            wordlist.append(line.strip())
        # print(wordlist)
        link = random.choice(wordlist)
        return link
    except:
        return 'http://www.sogou.com'

    # eval---指定函数1
def KW_getkeyword():
    wordlist = []
    path = os.path.join(BASE_DIR, 'newsblog\\VIPsetkeyword\\keywords.txt')
    for line in open(path, encoding='utf-8'):
        wordlist.append(line.strip())
    keyword = random.choice(wordlist)
    # print(a)  # print(wordlist)
    return keyword

# 结尾词随机函数        # eval---指定函数2
def KW_getbackword():
    wordlist = []
    path = os.path.join(BASE_DIR, 'newsblog\\VIPsetkeyword\\backwords.txt')
    for line in open(path, encoding='utf-8'):
        wordlist.append(line.strip())
    backword = random.choice(wordlist)
    # print(a)  # print(wordlist)
    return backword


def KW_getwords():
    huashulist = []
    huashu0 = '<img src="http://www.tbzhu.com/static/peoplemod/content/16.jpg" style="max-width:690px;margin:0pt auto;display:block" id="image_operate_29341563423196454"><br><img src="http://www.tbzhu.com/static/peoplemod/content/20.jpg" style="max-width:690px;margin:0pt auto;display:block"><br>'
    huashu1 = f"<p>    恭喜你！从今以后，你在淘宝可以省下大把的银子了~{KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}。</p>"
    huashu2 = f"<p>    教你领优惠券的公众号 {KW_getkeyword()}{KW_getbackword()}能查优惠券 找券平台能帮你省钱的~  {KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}。</p>"
    huashu3 = f"<p>    第一次关注我的人，找券平台你以前买过的很多东西在我们这里都有优惠券！ {KW_getkeyword()}{KW_getbackword()}  内心都是崩溃的，找券平台因为你会发现， {KW_getkeyword()}{KW_getbackword()} 找券平台在我们这里，你会发现很多东西用券后的价格真的爽爆！！ {KW_getkeyword()}{KW_getbackword()}</p>"
    huashu4 = f"<p>    【优惠券官网】，到里面搜一搜看有没有优惠券~~ {KW_getkeyword()}{KW_getbackword()}  一年帮你省下一台iphone8是妥妥滴， {KW_getkeyword()}{KW_getbackword()} 不要错过大额优惠 {KW_getkeyword()}{KW_getbackword()}。</p>"
    huashu5 = f"<p>{KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}</p>" \
              f"<p>{KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}</p>" \
              f"<p>{KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}  {KW_getkeyword()}{KW_getbackword()}</p>"
    huashulist.append(huashu0)
    huashulist.append(huashu1)
    huashulist.append(huashu2)
    huashulist.append(huashu3)
    huashulist.append(huashu4)
    huashulist.append(huashu5)
    return huashulist
